<?php
session_start();
$reqlevel="ADM,SUP,USE";
include ('../users2k/getlevel.php');
include("../urlstack-func.php");
require_once("../functions.php");
$myphpsessdir=str_replace("\\","/",session_save_path());
if($_REQUEST[debug]) echo "SAVE PATH=$myphpsessdir<br>";
$urlb=urlstack("http://".$_SERVER['HTTP_HOST'].$PHP_SELF."?".$_SERVER['QUERY_STRING'],0);
//echo "urlb: $urlb<br>";
session_register("urlb");
$ult=$PHP_SELF."?".$QUERY_STRING;
session_register("ult");
//$myphpsessdir='/tmp/phpsess/';
include("$mypath/makesql.php");
if (!isset($pag))
$pag=5;
$ordpreg=$HTTP_GET_VARS['idpreg'];
require_once("../adodb/adodb.inc.php");
require_once("../Connections/forms2.php");
$forms2->debug=$_REQUEST['debug'];
$datosvista__MMColParam = "1";
if (isset($HTTP_GET_VARS["idvista"]))
  {$datosvista__MMColParam = $HTTP_GET_VARS["idvista"];}

$forms2->debug=$debug;
//************* borro los listados de sessiones terminadas *********
$sessarr=array();
if ($handle = opendir($myphpsessdir)) {
  while (false !== ($file = readdir($handle))) { 
    if ($file != "." && $file !="..") { 
		array_push($sessarr,"'$file'");}
  }// end while
$SQL="DELETE FROM listados WHERE idsess NOT IN(".str_replace("sess_","",implode(",",$sessarr)).")";
$forms2->Execute($SQL);// or DIE("Garbagge Collector Error:$SQL<br>".$forms2->ErrorMsg()."$SQL<br>".__FILE__.': line '.__LINE__);
}

// ************ Para el redir de cada entidad ****************
$SQL="SELECT * FROM vistas WHERE idvista=$idvista";
$Myform=$forms2->Execute($SQL) or DIE ("No se pudo abrir la vista $idvista<br>$SQL<br>".$forms2->ErrorMsg());
if (!$Myform->EOF){
  $filterByUser=$Myform->Fields("filterByUser");
  $filterByGroup=$Myform->Fields("filterByGroup");
  $estilo=$Myform->Fields("estilo");
  $ident=$Myform->Fields("ident");}
  $datos=explode("*",$Myform->Fields("redir"));
  $redir=$datos[0];
  $layout=explode("*",$Myform->Fields("layout"));
  $layout_v=$layout[0];
  $layout_m=$layout[1];
  if ($Myform->Fields("SQL")<>"" AND $SQLids=="") $SQLids=$Myform->Fields("SQL");
  
if ($redir<>""){
	$tiporedir=$redir;
	$tiporedir=$tiporedir[0];
	$idredir=substr($redir,1);


	switch ($tiporedir){
	
	case "V":
	$SQL="SELECT layout FROM vistas WHERE idvista=$idredir";
	$vista=$forms2->Execute($SQL) or DIE ("No se pudo abrir la vista $idvista<br>".$forms2->ErrorMsg()."<br>$SQL<br>");
	$layout=$vista->Fields("layout");
	$go="/RenderView/viewnew.php";
	if ($layout<>"") $go="/RenderView/viewlayout.php";
    if (strstr($level,"ADM") or strstr($level,"SUP") or strstr($level,"EV".$idredir)){  
	       $go="/RenderEdit/editnew.php";
	       if ($layout<>"") $go="/RenderEdit/editlayout.php";
	}
	$basefile="$go?idvista=$idredir&origen=V";
	break;		
	case "C":
	$file="editnew";
	$SQL="SELECT layout FROM vistas WHERE idvista=$idredir";
	$vista=$forms2->Execute($SQL) or DIE ("No se pudo abrir la vista $idvista<br>".$forms2->ErrorMsg()."<br>$SQL<br>");
	$layout=$vista->Fields("layout");
	if ($layout<>"") $file="editlayv";
	$basefile="/RenderEdit/$file.php?idvista=$idredir&origen=C";
	break;
	case "I":
	$basefile="/RenderView/printvista.php?idvista=$idredir&origen=V";
	break;
	case "L":
	$basefile="/appfront/listar.php?idvista=$idredir";
	break;
	case "F":
	$SQL="SELECT layout FROM formularios WHERE idform=$idredir";
	$form=$forms2->Execute($SQL) or DIE ("No se pudo abrir la vista $idvista<br>".$forms2->ErrorMsg()."<br>$SQL<br>");
	$layout=$form->Fields("layout");
	$go="/RenderView/viewnew.php";
	if ($layout<>"") $go="/RenderView/viewlayout.php";
	if (strstr($level,"ADM") or strstr($level,"SUP") or strstr($level,"F".$idredir)) { 
	       $go="/RenderEdit/editnew.php";
	       if ($layout<>"") $go="/RenderEdit/editlayout.php";
	}
	$basefile="$go?idform=$idredir";
	break;	
	}
	
	$redir=$basedir.$basefile."&idap=$idap";
	
} Else {
    $tiporedir="V";
	$idredir=$idvista;
	$redir="../RenderView/viewnew.php?idvista=$idvista&origen=V&idap=$idap";
}  

// obtengo preguntas de la vista
$SQL="SELECT preguntas.* FROM preguntasvista INNER JOIN preguntas ON preguntasvista.idpreg=preguntas.idpreg 
	  WHERE idvista=$idvista 
	  ORDER BY preguntasvista.orden";
$preguntas=$forms2->Execute($SQL) or DIE ("No se pudo abrir la ccccc<br>".$forms2->ErrorMsg()."<br>$SQL<br>");

// para ver si muestro en el mapa
$SQL="SELECT preguntas.idpreg
      FROM preguntasvista inner join preguntas on preguntas.idpreg=preguntasvista.idpreg 
	  WHERE idopcion=58 AND idvista=$idvista";
$mipar=$forms2->Execute($SQL) or DIE ($forms2->ErrorMsg()."<br>$SQL<br>".__FILE__.":line:".__LINE__);
$mapa=false;
if (!$mipar->EOF) $mapa=true;


$SQL="SELECT * FROM vistas WHERE idvista = " . ($datosvista__MMColParam);
$datosvista=$forms2->Execute($SQL) or DIE($forms2->ErrorMsg()."<br>$SQL<br>");
$datosvista_numRows=0;
$datosvista__totalRows=$datosvista->RecordCount();

// para el modo de listar
$modos=explode(",",$datosvista->Fields("mode"));
if ($modo=="") {
$modo=$modos[0];
}

switch($modo){
case "borrada":
$estado=$modo;
$modomsg="Registros Borrados";
break;
case "temporal":
$estado=$modo;
$modomsg="Registros Temporales";
break;
case "validar":
$estado=$modo;
$modomsg="Registros para validar";
break;
default:
$modomsg="Registros Activos";
$estado="activa";
break;
}

$tabladest=explode("*",$Myform->Fields("redir"));
$tabladest=$tabladest[1];
$preg_orden=$idpreg;
include("ids_listar.php");
$idpreg=$preg_orden;
?><?php
   $Repeat1__numRows = $pag;
   $Repeat1__index= 0;
   $ID_numRows = $ID_numRows + $Repeat1__numRows;
?><?php
  // *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
  
  // set the record count
  $ID_total = $ID->RecordCount();
  
  // set the number of rows displayed on this page
  if ($ID_numRows < 0) {            // if repeat region set to all records
    $ID_numRows = $ID_total;
  } else if ($ID_numRows == 0) {    // if no repeat regions
    $ID_numRows = 1;
  }
  
  // set the first and last displayed record
  $ID_first = 1;
  $ID_last  = $ID_first + $ID_numRows - 1;
  
  // if we have the correct record count, check the other stats
  if ($ID_total != -1) {
    $ID_numRows = min($ID_numRows, $ID_total);
    $ID_first  = min($ID_first, $ID_total);
    $ID_last  = min($ID_last, $ID_total);
  }
  ?><?php
  // *** Recordset Stats: if we don't know the record count, manually count them
 
     // set the number of rows displayed on this page
    if ($ID_numRows < 0 || $ID_numRows > $ID_total) {
      $ID_numRows = $ID_total;
    }
  
    // set the first and last displayed record
   $ID_last  = min($ID_first + $ID_numRows - 1, $ID_total);
    $ID_first = min($ID_first, $ID_total);
?><?php $MM_paramName = ""; ?><?php
// *** Move To Record and Go To Record: declare variables

$MM_rs	  = &$ID;
$MM_rsCount   = $ID_total;
$MM_size      = $ID_numRows;
$MM_uniqueCol = "";
$MM_paramName = "";
$MM_offset = 0;
$MM_atTotal = false;
$MM_paramIsDefined = ($MM_paramName != "" && isset($$MM_paramName));
?><?php
// *** Move To Record: handle 'index' or 'offset' parameter

if (!$MM_paramIsDefined && $MM_rsCount != 0) {

	// use index parameter if defined, otherwise use offset parameter
	if(isset($index)){
		$r = $index;
	} else {
		if(isset($offset)) {
			$r = $offset;
		} else {
			$r = 0;
		}
	}
	$MM_offset = $r;

	// if we have a record count, check if we are past the end of the recordset
	if ($MM_rsCount != -1) {
		if ($MM_offset >= $MM_rsCount || $MM_offset == -1) {  // past end or move last
			if (($MM_rsCount % $MM_size) != 0) {  // last page not a full repeat region
				$MM_offset = $MM_rsCount - ($MM_rsCount % $MM_size);
			}
			else {
				$MM_offset = $MM_rsCount - $MM_size;
			}
		}
	}

	// move the cursor to the selected record
	for ($i=0;!$MM_rs->EOF && ($i < $MM_offset || $MM_offset == -1); $i++) {
		$MM_rs->MoveNext();
	}
	if ($MM_rs->EOF) $MM_offset = $i;  // set MM_offset to the last possible record
}
?><?php
// *** Move To Record: if we dont know the record count, check the display range

if ($MM_rsCount == -1) {

  // walk to the end of the display range for this page
  for ($i=$MM_offset; !$MM_rs->EOF && ($MM_size < 0 || $i < $MM_offset + $MM_size); $i++) {
    $MM_rs->MoveNext();
  }

  // if we walked off the end of the recordset, set MM_rsCount and MM_size
  if ($MM_rs->EOF) {
    $MM_rsCount = $i;
    if ($MM_size < 0 || $MM_size > $MM_rsCount) $MM_size = $MM_rsCount;
  }

  // if we walked off the end, set the offset based on page size
  if ($MM_rs->EOF && !$MM_paramIsDefined) {
    if (($MM_rsCount % $MM_size) != 0) {  // last page not a full repeat region
      $MM_offset = $MM_rsCount - ($MM_rsCount % $MM_size);
    } else {
      $MM_offset = $MM_rsCount - $MM_size;
    }
  }

  // reset the cursor to the beginning
  $MM_rs->MoveFirst();

  // move the cursor to the selected record
  for ($i=0; !$MM_rs->EOF && $i < $MM_offset; $i++) {
    $MM_rs->MoveNext();
  }
}
?><?php
// *** Move To Record: update recordset stats

// set the first and last displayed record
$ID_first = $MM_offset + 1;
$ID_last  = $MM_offset + $MM_size;
if ($MM_rsCount != -1) {
  $ID_first = $ID_first<$MM_rsCount?$ID_first:$MM_rsCount;
  $ID_last  = $ID_last<$MM_rsCount?$ID_last:$MM_rsCount;
}

// set the boolean used by hide region to check if we are on the last record
$MM_atTotal = ($MM_rsCount != -1 && $MM_offset + $MM_size >= $MM_rsCount);
?><?php
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

// create the list of parameters which should not be maintained
$MM_removeList = "&index=";
if ($MM_paramName != "") $MM_removeList .= "&".strtolower($MM_paramName)."=";
$MM_keepURL="";
$MM_keepForm="";
$MM_keepBoth="";
$MM_keepNone="";

// add the URL parameters to the MM_keepURL string
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
	$nextItem = "&".strtolower($key)."=";
	if (!stristr($MM_removeList, $nextItem)) {
		$MM_keepURL .= "&".$key."=".urlencode($val);
	}
}

// add the URL parameters to the MM_keepURL string
if(isset($HTTP_POST_VARS)){
	reset ($HTTP_POST_VARS);
	while (list ($key, $val) = each ($HTTP_POST_VARS)) {
		$nextItem = "&".strtolower($key)."=";
		if (!stristr($MM_removeList, $nextItem)) {
			$MM_keepForm .= "&".$key."=".urlencode($val);
		}
	}
}

// create the Form + URL string and remove the intial '&' from each of the strings
$MM_keepBoth = $MM_keepURL."&".$MM_keepForm;
if (strlen($MM_keepBoth) > 0) $MM_keepBoth = substr($MM_keepBoth, 1);
if (strlen($MM_keepURL) > 0)  $MM_keepURL = substr($MM_keepURL, 1);
if (strlen($MM_keepForm) > 0) $MM_keepForm = substr($MM_keepForm, 1);
?><?php
// *** Move To Record: set the strings for the first, last, next, and previous links

$MM_moveFirst="";
$MM_moveLast="";
$MM_moveNext="";
$MM_movePrev="";
$MM_keepMove = $MM_keepBoth;  // keep both Form and URL parameters for moves
$MM_moveParam = "index";

// if the page has a repeated region, remove 'offset' from the maintained parameters
if ($MM_size > 1) {
  $MM_moveParam = "offset";
  if (strlen($MM_keepMove)> 0) {
    $params = explode("&", $MM_keepMove);
    $MM_keepMove = "";
    for ($i=0; $i < sizeof($params); $i++) {
      list($nextItem) = explode("=", $params[$i]);
      if (strtolower($nextItem) != $MM_moveParam)  {
        $MM_keepMove.="&".$params[$i];
      }
    }
    if (strlen($MM_keepMove) > 0) $MM_keepMove = substr($MM_keepMove, 1);
  }
}

// set the strings for the move to links
if (strlen($MM_keepMove) > 0) $MM_keepMove.="&";
$urlStr = $PHP_SELF."?".$MM_keepMove.$MM_moveParam."=";
$MM_moveFirst = $urlStr."0";
$MM_moveLast  = $urlStr."-1";
$MM_moveNext  = $urlStr.($MM_offset + $MM_size);
$MM_movePrev  = $urlStr.(max($MM_offset - $MM_size,0));
?><?php
include "../RenderView/imagen.php";
include "../getmyvalue.php";
include "../RenderView/check.php";
include "../RenderView/text.php";
include "../RenderView/option.php";
include "../RenderView/fechahora.php";
//include "../RenderView/combo.php";
//include "../RenderView/veropciones.php";
include "../RenderView/tabla.php";
include "../RenderView/subform.php";
include "../firmaorigen.php";
include("cacheopciones.php");

//---------------------------------------------------------------------------------

?>
<html>
<head>
<title>Listado</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../estilo/verde.css" type="text/css">
<link rel="stylesheet" href="../style/style.css" type="text/css">
<!--java para abrir la ventana -->
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<!--java para abrir la ventana -->
<link rel="stylesheet" href="../jscript/jquery/plugins/tablesorter/themes/blue/style.css" type="text/css" media="print, projection, screen" />
</head>
<body class="seccioncolor" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="sql_form" action="print_sql.php" target="_blank" method="post">
<p align="center"><font face="Arial, Helvetica, sans-serif" size="5"><b><?php 
echo $datosvista->Fields("nombre");
if ($idu==1005747868) {?>&nbsp;
<img src="../ImagenCustom/b_selboard.png" width="20" height="20" onClick="document.sql_form.submit();">
<input type="hidden" name="SQLids" value="<?=$SQLids?>"><?php
}?>
  <br>
  </b><font size="2">
  <?php echo $datosvista->Fields("descripcion");
  if ($idpreg<>"") {
  $SQL="SELECT * FROM `preguntas` WHERE idpreg=$idpreg";
  $descorden=$forms2->Execute($SQL) or DIE($forms2->ErrorMsg()."<br>$SQL<br>");
  $ordby="ASC";
  if ($desc=="DESC") $ordby="DESC";
  echo "<br><font size=1>Ordenado por: ".$descorden->Fields("descripcion")." $ordby</font>";
  }?>
  </font></font></p>
  </form>
<table width="550" border="0" cellspacing="0" cellpadding="3" align="center">
  <tr> 
    <td width="135" nowrap valign="bottom"><font face="Arial, Helvetica, sans-serif" size="1"> 
      <?=$modomsg;?><br>
	  Resultados <?php echo $ID_first?> al <?php echo $ID_last?> de <?php echo $ID_total;?>
	  </font></td>
	<td width="80" valign="bottom"><font face="Arial, Helvetica, sans-serif" size="1"><?php 
	$modos=array_filter($modos,'trim');
	if ($idpreg<>"") $adddir="&idpreg=$idpreg";
	if ($desc<>"") $adddir=$adddir."&desc=$desc";
	foreach ($modos as $value) {
	if ($value<>$modo)
	echo "<a href='listar.php?idvista=$idvista&idap=$idap&modo=$value$adddir'>Listado $value</a><br>";
	}?></font></td>
    <td width="150"><div align="left">
	<font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><?php
	if (!$layout_v) {
	if(strstr($level,'ADM') or strstr($level,'EXLIS')){
		$idexp="$tiporedir$idredir";
		$orden=explode("*",$Myform->Fields("orden"));
		$SQL="SELECT * FROM vistas WHERE tipo='X' and idap=$idap and ident=$ident";
		$exportar=$forms2->Execute($SQL) or DIE($forms2->ErrorMsg()."<br>$SQL<br>");
		if (!$exportar->EOF) $idexp="V".$exportar->Fields("idvista");
		if ($orden[2]<>"") $idexp=$orden[2];?>
        <a href="explis.php?idap=<?php echo "$idap&idvista=$idvista&idexp=$idexp&idbusqueda=$PHPSESSID&idpreg=$idpreg&desc=$desc"; ?>"> 
        <img src="../ImagenCustom/Excel-XPs.gif" width="16" height="16" align="absmiddle" border="0">&nbsp;</a>
		<a href="explis.php?idap=<?php echo "$idap&idvista=$idvista&idexp=$idexp&idbusqueda=$PHPSESSID&idpreg=$idpreg&desc=$desc"; ?>">Exportar 
        a excel</a><?php 
	}
	}
	$filemapa="listarmapa.swf?idvista=$idvista&idap=$idap";
	if ($cantf>1) $filemapa="buscarmapa.swf?idvista=$vistasearch&idap=$idap";
	if ($mapa) {?>
		<br>
        <font color="#333333"><a href="../mapaprod/<?=$filemapa?>"><img src="../ImagenCustom/provincias.gif" width="16" height="16" align="absmiddle" border="0">&nbsp;ver 
        en el Mapa</a></font><?php 
		}?></font></div></td>
    <td width="93"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><?php 
	if ($layout_v) {
	echo "<a href='../Layouts/printlays/$layout_v?idap=$idap'><img src=\"../ImagenCustom/impresora.gif\" width=\"16\" height=\"16\" align=\"absmiddle\" border=\"0\">&nbsp;Imp/Excel</a>";
	} else {
	echo "&nbsp;";
	}
	if ($layout_m and strstr($level,"ADM")) {
	echo "<a href='../Layouts/printlays/$layout_m?idap=$idap'><img src=\"../ImagenCustom/mail.gif\" width=\"16\" height=\"16\" align=\"absmiddle\" border=\"0\">&nbsp;Mailer</a>";
	} else {
	echo "&nbsp;";
	}?></font></td>
    <td width="62"> <div align="right"> <a href="index.php"><font size="1" face="Arial, Helvetica, sans-serif">Inicio</font>&nbsp;<img src="../ImagenCustom/next.gif" align="absmiddle" border="0"></a><br>
        <a href="../gostack.php?back=1">&nbsp;</a><a href="../gostack.php?back=1"><font size="1" face="Arial, Helvetica, sans-serif">Volver</font></a> 
        <a href="../gostack.php?back=1"><img src="../ImagenCustom/next.gif" align="absmiddle" border="0"></a> 
      </div></td>
  </tr>
</table>
<table width="550" border="0" cellspacing="0" cellpadding="2" align="center" class="pregunta" height="60">
  <?php
while (($Repeat1__numRows-- != 0) && (!$ID->EOF)) {
 $id=$ID->Fields("id");?>
  <tr> 
    <td width="12%">
	<a href="<?=$redir."&id=".$ID->Fields("id");?>"><img src="../ImagenCustombig/folder.gif" border="0" alt="Abrir Consulta (Ver mas datos)" width="51" height="51"></a>
	<a href="addsel.php?id=<?php echo $ID->Fields("id")."&idvista=$idvista&ident=$ident";?>"><img src="../ImagenCustom/dbadd.gif" width="48" height="48" alt="Agregar a mi seleccion" border="0"></a><?php
	if (strstr($level,"ADM")) {?>
	<a href='rel.php?id=<?php echo $ID->Fields("id")."&idvista=$idvista&ident=$ident";?>'><img src='../ImagenCustom/dbrelbig.gif' width='48' height='48' alt='Ver relaciones' border='0'></a><?php 
	}?></td>
    <td width="78%"> 
      <table width="450" border="0" cellspacing="2" cellpadding="0"><?php 
		$preguntas->MoveFirst();
    while(!$preguntas->EOF){
	  $valor="";
	  //$tabladest=$preguntas->Fields("tabladest");
      $idform=$preguntas->Fields("idform");
	  $tipo=$preguntas->fields("idtipo");
	  $ancho=$preguntas->Fields("ancho");
	  $parametro1=$preguntas->Fields("param1");
	  $parametro2=$preguntas->Fields("param2");
	  $parametro3=$preguntas->Fields("param3");
	  $nombrecontrol=$preguntas->Fields("nombrecontrol");
	  $descripcion=stripslashes($preguntas->Fields("descripcion"));
	  $descripcion=str_replace('++basedir++',$basedir,$descripcion);
	  $descripcion=str_replace('++id++',$id,$descripcion);
	  
	  $idpreg=$preguntas->Fields("idpreg");
	  $idop=$preguntas->Fields("idopcion");	
		//---Para los Alias
		if ($tipo=="16"){
		  $param3=explode("*",$preguntas->Fields("param3"));
		  $alias=$param3[0];
		  $SQL="SELECT * FROM preguntas WHERE idpreg=$alias";
		  $alias=$forms2->Execute($SQL) or DIE ("No se pudieron abrir las preguntas de $idform<br>".$forms2->ErrorMsg()."<br>$SQL<br>");
		  // los alias tienen sus propios parametros si no tienen uso los de la pregunta origen
		  if ($ancho=="") $ancho=$alias->Fields("ancho");
		  if ($parametro1=="") $parametro1=$alias->Fields("param1");
		  if ($parametro2=="") $parametro2=$alias->Fields("param2");
		  // ----------------------------------------------------------------------------------
		  $nombrecontrol=$alias->Fields("nombrecontrol");
		  $idpreg=$alias->Fields("idpreg");
		  $idop=$alias->Fields("idopcion");
		  $tipo=$alias->Fields("idtipo");
		  //$tabladest=$alias->Fields("tabladest");
		  } 
    	//---Fin Alias
		?>
       
        <tr valign="top"> 
          <td width="150"> 
            <div align="right"><font face="MS Sans Serif" size="1" color="#515151"> 
              <?php echo $descripcion; ?>
              </font></div>
          </td>
		  <td width='3'><font face='Arial, Helvetica, sans-serif' size='1' color='#515151'>&nbsp;</font></td>
          <td width="300">
		  <font face="Arial, Helvetica, sans-serif" size="1" color="#515151"> <?php
		  
		  $valor=getvalue($idpreg);
		  include("./listcore.php");?>
          </font></td>
        </tr>
        <?php
	  $preguntas->Movenext();}?>
      </table>
    </td>
  </tr>
  <tr bgcolor="#999999"> 
    <td colspan="3" height="2"><img src="../ImagenCustom/shim.gif" width="1" height="1"></td>
  </tr>
  <?php 	
  $Repeat1__index++;
  $ID->MoveNext();
}
?>
</table>
<table width="60%" border="0" cellspacing="0" cellpadding="4" align="center">
  <tr> 
    <td width="76%"> 
      <div align="center"></div>
    </td>
  </tr>
</table>
<table width="60%" border="0" cellspacing="0" cellpadding="4" align="center">
  <tr> 
    <td width="76%"> 
      <div align="center"><font face="Arial, Helvetica, sans-serif" size="2">Resultados</font>
	  <font face="Arial, Helvetica, sans-serif" size="2"> 
        <?php echo $ID_first?>
        al 
        <?php echo $ID_last?>
        de 
        <?php echo $ID_total?>
        </font></div>
    </td>
  </tr>
</table>
<table width="60%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#999999">
  <tr> 
    <td width="76%"> 
      <div align="center"> 
        <table border="0" width="100%" align="center" class="mytr">
          <tr> 
            <td width="23%" align="center" class="seccioncolor"> <font face="Arial, Helvetica, sans-serif" size="2"> 
              <?php if ($MM_offset != 0) { ?>
              <a href="<?php echo $MM_moveFirst?>">Primera</a> 
              <?php } // end $MM_offset != 0 ?>
              </font></td>
            <td width="31%" align="center"> <font face="Arial, Helvetica, sans-serif" size="2"> 
              <?php if ($MM_offset != 0) { ?>
              <a href="<?php echo $MM_movePrev?>">Anterior</a> 
              <?php } // end $MM_offset != 0 ?>
              </font></td>
            <td width="23%" align="center"> <font face="Arial, Helvetica, sans-serif" size="2"> 
              <?php if (!$MM_atTotal) { ?>
              <a href="<?php echo $MM_moveNext?>">Pr&oacute;xima</a> 
              <?php } // end !$MM_atTotal ?>
              </font></td>
            <td width="23%" align="center"> <font face="Arial, Helvetica, sans-serif" size="2"> 
              <?php if (!$MM_atTotal) { ?>
              <a href="<?php echo $MM_moveLast?>">Ultima</a> 
              <?php } // end !$MM_atTotal ?>
              </font></td>
          </tr>
        </table>
      </div>
    </td>
  </tr>
</table>
<br>
<table width="60%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#999999">
<tr><td>
<form  action="listar.php">
<table align="center">

<?php 
$preguntas->Movefirst();?>
<tr> 
   <td width="100%"><div align="left"><font face="Arial, Helvetica, sans-serif" size="2">
     Ordenar listado por</font></div></td> 
 </tr><?php  
while (!$preguntas->EOF) {
if (!in_array($preguntas->Fields("idtipo"),Array(12,7,14,10,6,4))){?>
  <tr>
    <td width="100%"><div align="left"><font face="Arial, Helvetica, sans-serif" size="2"><?php 
	$checked="";
	if ($pregorden==$preguntas->Fields("idpreg")){$checked=" checked ";}?>
     <input type="radio" name="idpreg" value="<?php echo $preguntas->Fields("idpreg")?>" <?php echo $checked ?>><?php echo $preguntas->Fields("descripcion");?></font></div>
	</td>
  </tr><?php
  }
  $preguntas->Movenext();}?>
  <tr><td><br><div align="center">
    <input type="submit" value=" ASC ">&nbsp;
    <input type="submit" value="DESC" name="desc"></div>
  </td></tr>  
</table>
<input type="hidden" name="idvista" value="<?php echo $idvista?>"> 
<input type="hidden" name="idap" value="<?php echo $idap?>"> 
<input type="hidden" name="modo" value="<?php echo $modo?>"> 
</form>
</td></tr> 
</table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td valign="top"> 
      <div align="center"> 
        <table width="100%" border="0" cellspacing="0" cellpadding="2">
          <tr> 
            <td><font face="MS Sans Serif"> <font size="3"> <font size="2"> <font size="1"> 
              <?php
			/* for ($i=0;$i<count($urlstack);$i++){
			echo "<a href=\"".$urlstack[$i]."\">".$urlstack[$i]."</a><br>";
			} */
			?>
              &nbsp;</font></font></font></font></td>
          </tr>
        </table>
        <img src="../graphicart/80x31Microbanner.gif" width="88" height="31" align="absmiddle"> 
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../graphicart/php-small-trans-light.gif" width="88" height="31" align="absmiddle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="../graphicart/workswithmysql.gif" width="88" height="46" align="absmiddle"> 
      </div>
    </td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
  $ID->Close();
?>
<?php
  $datosvista->Close();
?>
